﻿using System;
using Rhino.ServiceBus.Hosting;
using Rhino.ServiceBus.Msmq;
using Utils;
using Messages;
using Rhino.ServiceBus;

namespace Server_MSMQ
{
    class Program
    {
        static void Main(string[] args)
        {
            PrepareQueues.Prepare("msmq://localhost/server_msmq", QueueType.Standard);

            Console.WriteLine("Listening messages to intercept");

            var host = new DefaultHost();
            host.Start<BackendBootStrapper>();

            Console.ReadLine(); ;
        }
    }

    public class MessageInterceptAndResponse : ConsumeOf<Message_Type1>
    {

        private readonly IServiceBus _serviceBus;

        public MessageInterceptAndResponse(IServiceBus serviceBus)
        {
            _serviceBus = serviceBus;
        }
        
        public void Consume(Message_Type1 msg)
        {
            Console.WriteLine("Incoming message: " + msg.Text);

            _serviceBus.Reply(new Message_Type2
            {
                Text = msg.Text + ". Adding something new"
            });
        }
    }
}
